<template>
  <Submenu :name="`${parentName}`">
    <template slot="title">
      <common-icon :type="parentItem.icon || ''"/>
      <span>{{ showTitle(parentItem) }}</span>
    </template>
    <template v-for="item in children">
      <template v-if="filterChildMenus[item.name] === '1'">   <!--屏蔽子菜单-->
        <template v-if="item.children && item.children.length === 1">
          <side-menu-item v-if="showChildren(item)" :key="`menu-${item.name}`" :parent-item="item"></side-menu-item>
          <menu-item v-else :name="getNameOrHref(item, true)" :key="`menu-${item.children[0].name}`"><common-icon :type="item.children[0].icon || ''"/><span>{{ showTitle(item.children[0]) }}</span></menu-item>
        </template>
        <template v-else>
          <side-menu-item v-if="showChildren(item)" :key="`menu-${item.name}`" :parent-item="item"></side-menu-item>
          <menu-item v-else :name="getNameOrHref(item)" :key="`menu-${item.name}`"><common-icon :type="item.icon || ''"/><span>{{ showTitle(item) }}</span></menu-item>
        </template>
      </template>
    </template>
  </Submenu>
</template>
<script>
import mixin from './mixin'
import itemMixin from './item-mixin'
export default {
  name: 'SideMenuItem',
  mixins: [ mixin, itemMixin ],
  data () {
    return {
      // 获取用户当前权限 用于屏蔽子菜单
      filterChildMenus: {
        'steering': '1',
        'address': '1',
        'cache': '1',
        'deploy': '0',
        'history': '1',
        'deploy_config': '0',
        'push': '0',
        'record': '1',
        'namespace': '0',
        'container': '1',
        'discover': '1',
        'cluster': '0',
        'deployment': '0',
        'containers': '0',
        'service': '0',
        'ingress': '1',
        'config': '0',
        'dev_test': '1',
        'uat_prod': '1',
        'sysconfig': '0',
        'user': '0',
        'access_group': '0'
      }
    }
  },
  created () {
    const auth = JSON.parse(sessionStorage.getItem('permission'))
    this.filterChildMenus.deploy = auth.child.deploy_view
    this.filterChildMenus.deploy_config = auth.child.deploy_config
    this.filterChildMenus.history = auth.child.deploy_history_view
    this.filterChildMenus.push = auth.child.push_view
    this.filterChildMenus.record = auth.child.push_record_view
    this.filterChildMenus.namespace = auth.child.env_view
    this.filterChildMenus.container = auth.child.containers_view
    this.filterChildMenus.discover = auth.child.router_view
    this.filterChildMenus.cluster = auth.child.namespace_view
    this.filterChildMenus.deployment = auth.child.deployment_view
    this.filterChildMenus.containers = auth.child.pods_view
    this.filterChildMenus.service = auth.child.service_view
    this.filterChildMenus.ingress = auth.child.ingress_view
    this.filterChildMenus.config = auth.child.config_view
    this.filterChildMenus.sysconfig = auth.child.sysconfig_view
    this.filterChildMenus.user = auth.child.user_view
    this.filterChildMenus.access_group = auth.child.user_group_view
  }
}
</script>
